import instance from "../utils/resqust";
import { userInfoType } from "../types/userInfo"


//用户注册
export const userReg = (userInfo:userInfoType) => {
    return instance.post("users", userInfo);
}


//用户登录
export const userLogin = (userInfo:userInfoType) => {
    return instance.post("login", userInfo);
}


//用户头像更新
export const userPoster = (objectId: string, url: string, session: string) => {
    console.log(objectId);
    
    return instance.put(`users/${objectId}`,{poster:url},{
        headers: {
            "X-LC-Session":session
        }
    });
}

//用户密码
// export const userPwd = (objectId:string,pwd:string,session:string) => {
//     return instance.put(`users/${objectId}`, { password: pwd }, {
//         headers: {
//             "X-LC-Session":session
//         }
//     });
// }

//更改密码
export const userPwd = (objectId: string, oldPwd: string, newPwd: string, session: string) => {
    return instance.put(`users/${objectId}/updatePassword`, {
        "old_password":oldPwd, "new_password":newPwd},{
            headers: {
            "X-LC-Session":session
        }
        }
    )
}


//用户查询
export const userLook = (num: number) => {
    let where = {
        key:0
    }
    where = JSON.stringify(where) as any;
    let skip = 10 * (num - 1);
    return instance.get("users", {
        params: {
            limit: 10,
            skip,
            count: 1,
            where
        }
    });
}


//用户查询
export const userProductFind = (productName:string) => {
    return instance.get("users", {
        params: {
            where: {
                productName,
            }
        }
    });
}



//用户申请详情查询
export const userProductDetilsFind = (username: string) => {
    let where:any = {
        username
    }
    where = JSON.stringify(where);
    return instance.get("classes/productApply", {
        params: {
            where
        }
    })
}